package com.fuxi.cloud.config.oss;

import cn.hutool.core.util.ObjectUtil;
import com.fuxi.cloud.common.util.MinioUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * JimuMinioConfig
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */

@Component("jimuMinioConfig")
@ConfigurationProperties(
        prefix = "jeecg.minio"
)
@ConditionalOnProperty(
        value = {"jeecg.uploadType"},
        havingValue = "minio",
        matchIfMissing = true
)
public class JimuMinioConfig {
    private static final Logger log = LoggerFactory.getLogger(JimuMinioConfig.class);
    private String minioUrl;
    private String minioName;
    private String minioPass;
    private String bucketName;

    @Bean
    public void initJimuMinio() {
        if (ObjectUtil.isNotEmpty(this.minioUrl)) {
            if (!this.minioUrl.startsWith("http")) {
                this.minioUrl = "http://" + this.minioUrl;
            }

            if (!this.minioUrl.endsWith("/")) {
                this.minioUrl = this.minioUrl.concat("/");
            }
        }

        try {
            MinioUtil.setMinioUrl(this.minioUrl);
            MinioUtil.setMinioName(this.minioName);
            MinioUtil.setMinioPass(this.minioPass);
            MinioUtil.setBucketName(this.bucketName);
        } catch (NoClassDefFoundError var2) {
            log.error("[JimuReport] 加载上传配置失败，Minio版本不匹配，请升级Minio依赖到8.0.3+", var2);
        }

    }

    public JimuMinioConfig() {
    }

    public String getMinioUrl() {
        return this.minioUrl;
    }

    public String getMinioName() {
        return this.minioName;
    }

    public String getMinioPass() {
        return this.minioPass;
    }

    public String getBucketName() {
        return this.bucketName;
    }

    public void setMinioUrl(String minioUrl) {
        this.minioUrl = minioUrl;
    }

    public void setMinioName(String minioName) {
        this.minioName = minioName;
    }

    public void setMinioPass(String minioPass) {
        this.minioPass = minioPass;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof JimuMinioConfig)) {
            return false;
        } else {
            JimuMinioConfig var2 = (JimuMinioConfig)o;
            if (!var2.canEqual(this)) {
                return false;
            } else {
                label59: {
                    String var3 = this.getMinioUrl();
                    String var4 = var2.getMinioUrl();
                    if (var3 == null) {
                        if (var4 == null) {
                            break label59;
                        }
                    } else if (var3.equals(var4)) {
                        break label59;
                    }

                    return false;
                }

                String var5 = this.getMinioName();
                String var6 = var2.getMinioName();
                if (var5 == null) {
                    if (var6 != null) {
                        return false;
                    }
                } else if (!var5.equals(var6)) {
                    return false;
                }

                String var7 = this.getMinioPass();
                String var8 = var2.getMinioPass();
                if (var7 == null) {
                    if (var8 != null) {
                        return false;
                    }
                } else if (!var7.equals(var8)) {
                    return false;
                }

                String var9 = this.getBucketName();
                String var10 = var2.getBucketName();
                if (var9 == null) {
                    if (var10 != null) {
                        return false;
                    }
                } else if (!var9.equals(var10)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof JimuMinioConfig;
    }

    @Override
    public int hashCode() {
        boolean var1 = true;
        byte var2 = 1;
        String var3 = this.getMinioUrl();
        int var7 = var2 * 59 + (var3 == null ? 43 : var3.hashCode());
        String var4 = this.getMinioName();
        var7 = var7 * 59 + (var4 == null ? 43 : var4.hashCode());
        String var5 = this.getMinioPass();
        var7 = var7 * 59 + (var5 == null ? 43 : var5.hashCode());
        String var6 = this.getBucketName();
        var7 = var7 * 59 + (var6 == null ? 43 : var6.hashCode());
        return var7;
    }

    public String toString() {
        return "JimuMinioConfig(minioUrl=" + this.getMinioUrl() + ", minioName=" + this.getMinioName() + ", minioPass=" + this.getMinioPass() + ", bucketName=" + this.getBucketName() + ")";
    }
}

